{layout name="layout/header" /}
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="root/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<link href="root/css/plugins/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet">

<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{$title}</h5>
                </div>
                <div class="ibox-content">
                    <p>
                        <button type="button" class="btn btn-primary btn-outline refresh">刷新</button>
                        <a type="button" class="btn btn-primary btn-outline" href="{:url('index')}">返回列表页</a>
                    </p>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">款项</label>
                            <div class="col-sm-11">
                                <select class="form-control m-b" name="cash_type_id" v-model="cash_type_id">
                                    <option value="0" >请选择款项</option>
                                    <option :value="i.id" v-for="i in cash_type">{{i.name}}</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-1 control-label">费用</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="price" name="price">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">类型</label>
                            <div class="col-sm-11">
                                <select class="form-control m-b" name="type" v-model="type">
                                    <option value="0" >请选择类型</option>
                                    <option value="1" >收入</option>
                                    <option value="2" >支出</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">付款时间</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control datetimepicker" id="time" name="time" data-id="time" v-model="time" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">备注</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="remark" name="remark">

                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-primary" @click="submit" type="submit">保存内容</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>
<script src="root/js/plugins/fancybox/jquery.fancybox.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="root/js/plugins/summernote/summernote.min.js"></script>
<script src="root/js/plugins/summernote/summernote-zh-CN.js"></script>
<script>
    var data = {$data};
    var url = "{$url}";

    if (data == 1) {
        data = {
            id: 0,
            cash_type_id:0,
            time:'',
            type:0,
            price:'',
            remark:'',
        }
    }
    //1
    data.cash_type = {$cash_type};
    data.pid = {$pid};
    new Vue({
        el: "#app",
        data: data,
        methods: {
            submit:function () {
                var _this = this;
                $("#form").validate({
                    rules:{
                        time:{
                            required:true,
                        },
                        cash_type_id:{
                            min:1,
                        },
                        type:{
                            min:1,
                        },
                        price:{
                            required:true,
                            digits:true,
                        },

                    },
                    messages:{

                    }
                })
                if($("#form").valid()) {

                    $.post(url,data,function (res) {
                        layer.msg(res.msg);

                        if(res.code==1){
                            setTimeout(function () {
                                window.location.href= "{:url('index')}"+"/pid/"+_this.pid;
                            },1500)
                        }
                    },'json')
                }

            }
        },
        mounted: function () {
            checks();
            $('.fancybox').fancybox({
                openEffect: 'none',
                closeEffect: 'none'
            });
            $('.summernote').summernote({
                lang:'zh-CN',
                disableDragAndDrop: true,
                // 重写图片上传
                onImageUpload: function(files, editor, $editable) {
                    sendFile(files[0],editor,$editable);
                },
                onblur:function () {
                    var field = $(this).parent().prev().attr('data-field')
                    data[field] = $(this).code();
                }
            });
            $('.datetimepicker').datetimepicker({
                format:'yyyy-mm-dd',
                language:  'zh-CN',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                maxView:3,
                minView:2,
                forceParse: 0,
            });
        }
    });
</script>

<script>
    $('#time').datetimepicker().on('hide', function (ev) {
        console.log($(this).val());
        var id = $(this).attr('data-id');
        data[id] = $(this).val();
    })
    $('#end').datetimepicker().on('hide', function (ev) {
        console.log($(this).val());
        var id = $(this).attr('data-id');
        data[id] = $(this).val();
    })
</script>
